<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">{{msg}}</div>
  <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
  <p></p>
  <input type="text">
  <script>
   const p = document.querySelector('p')
   const ipt = document.querySelector('input')
   const vm = new Vue({
      el: '#app',
      data: {
        msg: '哈哈哈'
      }
   })
   console.log(vm);
    const data = { name: 'zs' }
    const _data = {}
    Object.defineProperty(_data, 'name', {
      get: function reactiveGetter(){
        return data.name
      },
      set: function reactiveSetter(newVal){
        console.log(newVal);
        data.name = newVal // 同步数据
        console.log(data);
        // 同步视图
        p.innerHTML = newVal
        ipt.value = newVal
      }
    })
    console.log(_data);
    // _data.name = 'lisi'
    // 先同步一次视图
    p.innerHTML = _data.name
    ipt.value = _data.name
    // 视图发生修改后, 将视图的值同步给_data, 自动执行set函数
    ipt.addEventListener('input',(e)=>{
      _data.name = e.target.value
    })

    // 
    // Object.defineProperty 方法中有一个set函数, 数据发生修改后, 将最新的值同步
    // get 值的返回
  </script>
</body>
</html>